import datetime as dt
import time
from . import strutil


# 取得标准日期格式
def get_std_timestamp_format():
    return '%Y-%m-%d %H:%M:%S'


def get_std_date_format():
    return '%Y-%m-%d'


def get_std_time_format():
    return '%H:%M:%S'


# 取得毫秒级时间戳
def get_timestamp():
    return int(round(time.time() * 1000))


# 取得秒级时间戳
def get_seconds():
    return int(time.time())


# 秒数转十六进制
def seconds2hex(seconds: int, order=strutil.ORDER_BIG):
    ba = seconds.to_bytes(4, order)
    return strutil.bytes2hex(ba)


# 秒数转日期
def seconds2timestamp(seconds: int):
    return dt.datetime.fromtimestamp(seconds).strftime(get_std_timestamp_format())


# 字节转时间戳
def bytes2seconds(src: bytes, order=strutil.ORDER_BIG):
    return int.from_bytes(src, order)


# 十六进制转日期
def hex2timestamp(hex: str):
    ba = strutil.hex2bytes(hex)
    seconds = bytes2seconds(ba)
    return seconds2timestamp(seconds)
